Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

nice_things/fs/readlink.sh

Since 0.3.0 · Source

import "{ readlink }" from nice_things/fs/readlink.sh

Synopsis
readlink <file>

Configuration

Description
Print value of a symbolic link.

Note

This is not a pure sh implementation because it depends on the external ls utility to read the target of the symlink. This works consistently because the output of ls is strictly specified in POSIX, but it means this function can be slower than most other functions in the framework.

Options

Operands
<file>: Path to a symbolic link.

Stdin

Stdout
The result is printed to stdout, trailed by a line-feed character.

Stderr

Exit status

  • 0: Successful completion.
  • 22: <file> is not a symbolic link.
  • 123: Unexpected error (abort).

Abort
Aborts on unexpected error.

Usage examples

# Read the value of a link
link_target=$(readlink /path/to/link)